package com.zhongyu.controller;

import com.zhongyu.pojo.Provider;
import com.zhongyu.service.ProviderService;
import com.zhongyu.vo.GoodsTypeVo;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.ProviderVo;
import com.zhongyu.vo.ResultVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
/*
供应商
 */
@RestController
@RequestMapping("/jibenxinxi/gys/")
public class ProviderController {

    @Resource
    private ProviderService providerService;

    @GetMapping("/search/{pageNo}/{pageSize}")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize, ProviderVo providerVo) {
        PageResult pageResult = providerService.searchAll(pageNo, pageSize, providerVo);
        return ResultVo.success(pageResult);
    }
    @GetMapping("/list")
    public ResultVo list(){
        List<Provider> list= providerService.searchAll();
        return  ResultVo.success(list);

    }
    @PostMapping("/update")
    @RequiresPermissions("gys:update")
    public ResultVo update(@RequestBody Provider provider, HttpSession session) {
        try {
            providerService.update(provider);
            return ResultVo.success("修改供应商成功!");
        }catch (Exception ex){
            return ResultVo.failure("修改供应商失败!",ex);
        }
    }

    @GetMapping("/del")
    @RequiresPermissions("gys:del")
    public ResultVo del(Integer id) {
        try {
            providerService.del(id);
            return ResultVo.success("删除供应商成功!");
        } catch (Exception ex) {
            return ResultVo.failure("删除供应商失败！", ex);
        }
    }
    @PostMapping("/add")
    @RequiresPermissions("gys:add")
    public ResultVo add(@RequestBody Provider provider, HttpSession session){
        try{
            providerService.add(provider);
            return ResultVo.success("添加供应商成功!");
        }catch (Exception ex){
            return ResultVo.failure("添加供应商失败!",ex);
        }
    }
}
